/*
 * =====================================================================================
 *
 *       Filename:  array.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  03/20/12 13:55:59
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  randyli (randy), randyli@tencent.com
 *        Company:  Tencent
 *
 * =====================================================================================
 */


#ifndef  ARRAY_INC
#define  ARRAY_INC
#include "tree.h"
//the symbol table
typedef struct _smt_element
{
	RB_ENTRY(_smt_element) link;
	char* key;
	int   key_len;
	void* data;
}smt_element;

typedef struct _smt_tree smt_tree;
RB_HEAD(_smt_tree, _smt_element);

typedef struct _smt_array
{
	smt_element* elements;
	smt_tree     tree;
	int length;
	int free_num;
}smt_array;

int smt_array_new(smt_array** a);
int smt_array_set(smt_array* a, const char* key, int key_len, void* data);
void* smt_array_index_get(smt_array* a, int index);
void* smt_array_assoc_get(smt_array* a, const char* key, int key_len);
int smt_array_destory(smt_array* a);

#endif   /* ----- #ifndef ARRAY_INC  ----- */
